from ast import List

from tqdm import main


class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right
class Solution:
    def pathSum(self, root: TreeNode, target: int) -> List[List[int]]:
        if not root:
            return []
        res = []

        def dfs(node, target, path):
            if node is None:
                return   
            path.append(node.val)
            target -= node.val
            if target == 0 and node.left is None and node.right is None:
                res.append(path[:])
            dfs(node.left, target, path)
            dfs(node.right, target, path)
            path.pop()
        
        dfs(root, target, [])
        return res


if __name__ == '__main__':
    root = TreeNode(1)
    root.left = TreeNode(2)
    root.right = TreeNode(3)
    root.left.left = TreeNode(4)
    root.left.right = TreeNode(5)